﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Xml;
using Logic.SocialNetworks.EventBrite;
using System.Reflection;


namespace Logic.SocialNetworks
{
    /// <summary>
    /// Eventbrite's popular event registration service has now opened up its platform to developers to extend the functionality of Eventbrite and/ or import your data into your existing applications!
    /// Eventbrite API
    /// </summary>
    public class Eventbrite
	{
		#region Consts
		private const string EVENT_LIST_ATTENDEES_URL = @"{0}event_list_attendees?{1}&id={2}&count={3}";
        private const string CONNECTION_STRING = @"https://www.eventbrite.com/xml/";
		private const string NEW_EVENT_URL = @"{0}event_new?{1}&title={2}&description={3}&start_date={4}&end_date={5}&timezone={6}&privacy={7}&status={8}&currency={9}";
		private const string NEW_EVENT_URL_VENUE = @"{0}event_new?{1}&title={2}&description={3}&start_date={4}&end_date={5}&timezone={6}&privacy={7}&status={8}&currency={9}&venue_id={10}&organizer_id={11}";
		private const string EVENT_LIST_ATTENDEES_PAGE_URL = @"{0}event_list_attendees?{1}&id={2}&count={3}&page={4}";
		private const string USER_LIST_ORGENIZERS = @"{0}user_list_organizers?{1}&email={2}&passwd={3}";
		private const string UPDATE_EVENT_URL = @"{0}event_new?{1}&id={2}&title={3}&description={4}&start_date={5}&end_date={6}&timezone={7}&privacy={8}&status={9}";
		private const string NEW_TICKET_URL = @"{0}ticket_new?{1}&event_id={2}&name={3}&price={4}&quantity={5}&max={6}";
		private const string UPDATE_TICKET_URL = @"{0}ticket_update?{1}&id={2}&name={3}&price={4}&quantity={5}";
		private const string NEW_ORGANIZER_URL = @"{0}organizer_new?{1}&name={2}&description={3}";
		private const string UPDATE_ORGANIZER_URL = @"{0}orgenizer_new?{1}&id={2}&name={3}&description={4}";
		private const string ORGANIZER_LIST_EVENTS_URL = @"{0}organizer_list_events?{1}&id={2}";
		private const string NEW_VENUE_URL = @"{0}venue_new?{1}&organizer_id={2}&venue={3}&adress={4}&city={5}&region={6}&country_code={7}";
		private const string UPDATE_VENUE_URL = @"{0}venue_update?{1}&id={2}&venue={3}&adress={4}&city={5}&region={6}";
		private const string GET_USER_URL = @"{0}user_get?{1}";
		private const string USER_LIST_EVENTS_URL = @"{0}user_list_events?{1}";
		private const string GET_EVENT_URL = @"{0}event_get?{1}&id={2}";

		/// <summary>
		/// {0}=CONNECTION_STRING,{1}=Email,{2}=Password
		/// </summary>
		private const string NEW_USER_URL = @"{0}user_new?email={1}&passwd={2}";

		/// <summary>
		/// The secure method of authentication hides your login information and instead passes a user_key into the api.
		/// If a user_key provided, the API will validate it against the Eventbrite user database.
		/// If the user_key is valid and authenticated, the method call will continue. 
		/// If the user_key is not valid or presented an incorrect password and the method requires authentication, an XML error message is returned:
		/// To ensure maximum safety, only authentication requests made over SSL will be processed. 
		/// So all your API calls should start with "https://".
		/// </summary>
		private const string SECURE_AUTHENTICATION_URL = @"app_key={0}&user_key={1}";
		/// <summary>
		/// The Basic level of authentication involves providing the parameters "user" and "password" to each method call along with other parameters.
		/// If a user and password are provided, the API will validate them against the Eventbrite user database.
		/// If the user is valid and authenticated, the method call will continue.
		/// If the user is not valid or presented an incorrect password and the method requires authentication, an XML error message is returned:
		/// To ensure maximum safety, only authentication requests made over SSL will be processed.
		/// So all your API calls should start with "https://".
		/// </summary>
		private const string BASIC_AUTHENTICATION_URL = @"app_key={0}&user={1}&password={2}";

		#endregion


		public Eventbrite(string appKey, string userKey)
        {
            this.APP_KEY = appKey;
            this.USER_KEY = userKey;
        }
        //public Eventbrite(string appKey, string email, string password) 
        //{
        //    this.APP_KEY = appKey;
        //    BasicClientCredentials(email, password);
        //}
         
        #region Authentication Keys

        /// <summary>
        /// The application key is a string assigned by Eventbrite which identifies the application making the method call.
        /// This is separate from user authentication, which identifies the Eventbrite user using the application. For example, if Eventbrite user xyz@mail.com is using a Dashboard widget to display events from a Smart Calendar, "app_key" would identify the Dashboard widget and "user"/"password" would identify the user.
        /// A valid application key is required for any interaction with the Eventbrite API
        /// </summary>
         private string APP_KEY { get; set; }
        /// <summary>
        /// The user key is a unique string assigned by Eventbrite which identifies the user making an API call.
        /// This replaces basic username/password authentication.
        /// A valid user key is the recommended method for user authentication with the Eventbrite API.
        /// </summary>
        private string USER_KEY { get; set; }//= @"12662331703440714269";
        #endregion

        public enum Count:int
        {
            [StringValue("")]
            All = 0,
            
            First = 1,
            First50 = 50
        }

        #region Event Methods

        private Logic.ContentServiceResponse<string> CreateEvent(string EventTitle, string EventDescription, DateTime StartDate, DateTime EndDate, string TimeZone, int Privacy, string eventMode)
        {
            string url = string.Format(NEW_EVENT_URL, CONNECTION_STRING, SecureClientCredentials(), EventTitle, EventDescription, SetDateFormat(StartDate), SetDateFormat(EndDate), TimeZone, Privacy, eventMode, "");
            Logic.ContentServiceResponse<string> response = new ContentServiceResponse<string>();
            try
            {
                XmlDocument result = GetWebServiceResponseAsString(url, 60000);

                if (result.DocumentElement["id"] != null && result.DocumentElement["status"].InnerText.ToLower() == "ok")
                {
                    response.Content = result.DocumentElement["id"].InnerText;
                    response.ResultOption = ServiceResultOptions.Success;
                }
                else
                {
                    response.Message = result.DocumentElement["error_message"].InnerText;
                    response.ResultOption = ServiceResultOptions.OperationFailure;
                    response.Content = response.Message;
                }
            }
            catch (Exception ex)
            {
                response.ResultOption = ServiceResultOptions.SystemException;
                response.Content = ex.Message;
            }
            return response;

        }
        /// <summary>
        /// This method creates a new event.
        /// </summary>
        /// <param name="EventTitle">The event title</param>
        /// <param name="EventDescription">The event description</param>
        /// <param name="StartDate">The event start date and time, in ISO 8601 format (e.g., "2007-12-31 23:59:59")</param>
        /// <param name="EndDate">The event end date and time, in ISO 8601 format (e.g., "2007-12-31 23:59:59")</param>
        /// <param name="TimeZone">The event time zone in relation to GMT (e.g., "GMT+01", "GMT+02", "GMT-01")</param>
        /// <param name="Privacy">0 for a private event, 1 for a public event. If not provided, will default to 1</param>
        /// <param name="startHour">The hour the event start</param>
        /// <param name="startMinute">The minute the event start</param>
        /// <param name="startAmPm">The time the event start in am or pm</param>
        /// <param name="endHour">The hour the event ends</param>
        /// <param name="endMinute">The minute the event ends</param>
        /// <param name="endAmPm">The time the event ends in am or pm. "1" for AM or "2" for PM</param>
        /// <param name="eventMode">Should be "live" or "draft"</param>
        /// <param name="venueID">The event venue ID. null if you don't have one. The venue must have been previously created using VenueNew method.</param>
        /// <param name="orgenizerID">The event organizer ID. null if you don't have one. The organizer must have been previously created using OrganizerNew method.</param>
        /// <returns>It returns the ID of the newly created event</returns>
        public Logic.ContentServiceResponse<string> CreateEvent(string EventTitle, string EventDescription, DateTime StartDate, DateTime EndDate, string TimeZone, int Privacy, string eventMode, string venueID, string orgenizerID)
        {
            string url = string.Empty;
            if (string.IsNullOrEmpty(venueID) || string.IsNullOrEmpty(orgenizerID))
            {
                 url = string.Format(NEW_EVENT_URL, CONNECTION_STRING, SecureClientCredentials(), EventTitle, EventDescription, SetDateFormat(StartDate), SetDateFormat(EndDate), TimeZone, Privacy, eventMode, "");
            }
            else
            {
                url = string.Format(NEW_EVENT_URL_VENUE, CONNECTION_STRING, SecureClientCredentials(), EventTitle, EventDescription, SetDateFormat(StartDate), SetDateFormat(EndDate), TimeZone, Privacy, eventMode, "", venueID, orgenizerID);
            }
            Logic.ContentServiceResponse<string> response = new ContentServiceResponse<string>();
            try
            { 
                XmlDocument result = GetWebServiceResponseAsString(url, 60000);

                if (result.DocumentElement["id"] != null && result.DocumentElement["status"].InnerText.ToLower() == "ok")
                {
                    response.Content = result.DocumentElement["id"].InnerText;
                    response.ResultOption = ServiceResultOptions.Success;
                }
                else
                {
                    response.Message = result.DocumentElement["error_message"].InnerText;
                    response.ResultOption = ServiceResultOptions.OperationFailure;
                    response.Content = response.Message;
                }
            }
            catch (Exception ex)
            {
                response.ResultOption = ServiceResultOptions.SystemException;
                response.Content = ex.Message;                
            }
            return response;

        }

		/// <summary>
        /// This method returns a list of attendees for a given event. If no authentication is passed, only publicly available attendee records will be returned
        /// </summary>
        /// <param name="EventId">The ID of the event</param>
        /// <param name="Count">Limit the number of attendees returned</param>
        /// <returns>This method returns a list of attendees for a given event</returns>
        public Logic.ContentServiceResponse<Attendees> GetAttendeesListByEventID(string eventId, Count atenndeesCount)
        {
            string url = string.Format(EVENT_LIST_ATTENDEES_URL, CONNECTION_STRING, SecureClientCredentials(), eventId, atenndeesCount.GetStringValue());
            Logic.ContentServiceResponse<Attendees> response = new ContentServiceResponse<Attendees>();

            try
            {
                XmlDocument result = GetWebServiceResponseAsString(url, 60000);
                if (result.DocumentElement["attendee"] != null)
                {
                    response.Content = new Attendees(result);
                    response.ResultOption = ServiceResultOptions.Success;
                }
                else
                {
                    response.ResultOption = ServiceResultOptions.OperationFailure;
                    response.Message = result.DocumentElement["error_message"].InnerText;
                }

            }
            catch (Exception ex)
            {

                response.Message = ex.Message;
                response.ResultOption = ServiceResultOptions.SystemException;
            }
            
            return response;
        }

        /// <summary>
        /// This method returns a list of attendees for a given event. If no authentication is passed, only publicly available attendee records will be returned
        /// </summary>
        /// <param name="EventId">The ID of the event</param>
        /// <param name="Count">Limit the number of attendees returned</param>
        /// <param name="Page">Allows for paging through the results of a query. Default is 1. Page size will be setted with "count" parameter</param>
        /// <returns>This method returns a list of attendees for a given event</returns>
        public  Attendees EventListAttendees(string EventId, int Count, int Page)
        {
            return new Attendees(GetWebServiceResponseAsString(string.Format(EVENT_LIST_ATTENDEES_PAGE_URL, CONNECTION_STRING, SecureClientCredentials(), EventId, Count, Page), 60000));
        }

        /// <summary>
        /// This method returns the data for a given event
        /// </summary>
        /// <param name="EventId">The ID of the requested event</param>
        /// <returns></returns>
        public  Event EventGet(string EventId)
        {
            return new Event(GetWebServiceResponseAsString(string.Format(GET_EVENT_URL, CONNECTION_STRING, SecureClientCredentials(), EventId), 60000));
        }

        /// <summary>
        /// This method creates a new event.
        /// </summary>
        /// <param name="EventId">The ID of the event to update</param>
        /// <param name="EventTitle">The event title</param>
        /// <param name="EventDescription">The event description</param>
        /// <param name="StartDate">The event start date and time, in ISO 8601 format (e.g., "2007-12-31 23:59:59")</param>
        /// <param name="EndDate">The event end date and time, in ISO 8601 format (e.g., "2007-12-31 23:59:59")</param>
        /// <param name="TimeZone">The event time zone in relation to GMT (e.g., "GMT+01", "GMT+02", "GMT-01")</param>
        /// <param name="Privacy">0 for a private event, 1 for a public event. If not provided, will default to 1</param>
        /// <param name="Status">The event status. Allowed values are "draft", "live", "canceled", "deleted"</param>
        /// <returns>It returns the ID of the newly created event</returns>
        public  Event EventUpdate(int EventId, string EventTitle, string EventDescription, string StartDate, string EndDate, string TimeZone, int Privacy, string Status)
        {
            return new Event(GetWebServiceResponseAsString(string.Format(UPDATE_EVENT_URL, CONNECTION_STRING, SecureClientCredentials(), EventTitle, EventDescription, StartDate, EndDate, TimeZone, Privacy, Status), 60000));
        }

        #endregion

        #region Ticket Methods

        /// <summary>
        /// This method creates new fixed-price or donation ticket types
        /// </summary>
        /// <param name="EventId">The event ID. The event must have been previously created using EventNew method.</param>
        /// <param name="Name">The ticket name</param>
        /// <param name="Price">The ticket price. Enter 0.00 for free tickets. Leave blank for a donation</param>
        /// <param name="Quantity">The number of tickets available. Not required for donations</param>
        /// <returns>It returns the ID of the newly created ticket</returns>
        public  ContentServiceResponse<Ticket> TicketNew(int EventId, string Name, float Price, int Quantity)
        {
            ContentServiceResponse<Ticket> ticket = new ContentServiceResponse<Ticket>();
            try
            {
                XmlDocument result = GetWebServiceResponseAsString(string.Format(NEW_TICKET_URL, CONNECTION_STRING, SecureClientCredentials(), EventId, Name, Price, Quantity, 1), 60000);
                if (result.DocumentElement["id"] != null)
                {
                    ticket.Content = new Ticket(result);
                    ticket.ResultOption = ServiceResultOptions.Success;
                }
                else
                {
                    ticket.ResultOption = ServiceResultOptions.OperationFailure;
                    ticket.Message = result.DocumentElement["error_message"].InnerText;
                }

            }
            catch (Exception ex)
            {

                ticket.SetException(ex);
            }

            return ticket;
        }


        /// <summary>
        /// This method updates an existing ticket type. Only the fields passed as arguments will be modified. 
        /// </summary>
        /// <param name="TicketId">The ticket ID</param>
        /// <param name="Name">The ticket name</param>
        /// <param name="Price">The ticket price. Enter 0.00 for free tickets. Leave blank for a donation. If tickets are already sold, price will not change.</param>
        /// <param name="Quantity">The number of tickets available. Not required for donations</param>
        /// <returns>It returns the ID of the updated ticket</returns>
        public  Ticket TicketUpdate(int TicketId, string Name, float Price, int Quantity)//check what this method returns. the API documentation said event but it should be ticket
        {
            return new Ticket(GetWebServiceResponseAsString(string.Format(UPDATE_TICKET_URL, CONNECTION_STRING, SecureClientCredentials(), TicketId, Name, Price, Quantity), 60000));
        }

        #endregion

        #region Orgenizer Methods


        /// <summary>
        /// This method creates a new organizer
        /// </summary>
        /// <param name="Name">The organizer name</param>
        /// <param name="Description">The organizer description</param>
        /// <returns>It returns the ID of the newly created organizer</returns>
        public ContentServiceResponse<string> OrganizerNew(string Name, string Description)
        {
            string url = string.Format(NEW_ORGANIZER_URL, CONNECTION_STRING, SecureClientCredentials(), Name, Description);
            Logic.ContentServiceResponse<string> response = new ContentServiceResponse<string>();
            try
            {
                XmlDocument result = GetWebServiceResponseAsString(url, 60000);

                if (result.DocumentElement["id"] != null && result.DocumentElement["status"].InnerText.ToLower() == "ok")
                {
                    response.Content = result.DocumentElement["id"].InnerText;
                    response.ResultOption = ServiceResultOptions.Success;
                }
                else
                {
                    response.Message = result.DocumentElement["error_message"].InnerText;

					if (response.Message == "This organizer name already exists.")
					{
						response.ResultOption = ServiceResultOptions.DuplicateFailure;
					}
					else
					{
						response.ResultOption = ServiceResultOptions.OperationFailure;
					}
                    response.Content = response.Message;
                }
            }
            catch (Exception ex)
            {
                response.ResultOption = ServiceResultOptions.SystemException;
                response.Content = ex.Message;
            }
            return response;
        }

        /// <summary>
        /// This method updates an existing organizer
        /// </summary>
        /// <param name="OrganizerId">The organizer ID</param>
        /// <param name="OrganizerName">The orgenizer name</param>
        /// <param name="OrganizerDescription">The organizer description</param>
        /// <returns>It returns the ID of the updated organizer</returns>
        public  Organizer OrganizerUpdate(int OrganizerId, string OrganizerName, string OrganizerDescription)
        {
            return new Organizer(GetWebServiceResponseAsString(string.Format(UPDATE_ORGANIZER_URL, CONNECTION_STRING, SecureClientCredentials(), OrganizerId, OrganizerName, OrganizerDescription), 60000));
        }


        /// <summary>
        /// This method lists the events created by this organizer
        /// </summary>
        /// <param name="OrganizerId">The organizer ID</param>
        /// <returns>It returns the ID of the updated organizer</returns>
        public  Events OrganizerListEvents(int OrganizerId)
        {
            return new Events(GetWebServiceResponseAsString(string.Format(ORGANIZER_LIST_EVENTS_URL, CONNECTION_STRING, SecureClientCredentials(), OrganizerId), 60000));
        }

        #endregion

        #region Venues Methods

        /// <summary>
        /// This method creates a new venue
        /// </summary>
        /// <param name="OrganizerId">The ID of the related organizer. The organizer must have been previously created using OrganizerNew method.</param>
        /// <param name="VenueName">The venue name</param>
        /// <param name="VenueAdress">The venue adress</param>
        /// <param name="VenueCity">The venue city</param>
        /// <param name="VenueCounty">The venue state/province/county/territory depending on the country. 2-letter state code is required for US addresses</param>
        /// <param name="venueCountryCode">2-letter country code, according to the ISO 3166 format. US for the united states of america
        /// you can find the list here: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm</param>
        /// <returns>It returns the ID of the newly created venue</returns>
        public ContentServiceResponse<string> VenueNew(string OrganizerId, string VenueName, string VenueAdress, string VenueCity, string VenueCounty, string venueCountryCode)
        {
            string url = string.Format(NEW_VENUE_URL, CONNECTION_STRING, SecureClientCredentials(), OrganizerId, HttpUtility.UrlEncode(VenueName), HttpUtility.UrlEncode(VenueAdress), HttpUtility.UrlEncode(VenueCity), HttpUtility.UrlEncode(VenueCounty), HttpUtility.UrlEncode(venueCountryCode));
            Logic.ContentServiceResponse<string> response = new ContentServiceResponse<string>();
            try
            {
                XmlDocument result = GetWebServiceResponseAsString(url, 60000);

                if (result.DocumentElement["id"] != null && result.DocumentElement["status"].InnerText.ToLower() == "ok")
                {
                    response.Content = result.DocumentElement["id"].InnerText;
                    response.ResultOption = ServiceResultOptions.Success;
                }
                else
                {
                    response.Message = result.DocumentElement["error_message"].InnerText;
                    response.ResultOption = ServiceResultOptions.OperationFailure;
                    response.Content = response.Message;
                }
            }
            catch (Exception ex)
            {
                response.ResultOption = ServiceResultOptions.SystemException;
                response.Content = ex.Message;
            }
            return response;
        }


        /// <summary>
        /// This method creates a new venue
        /// </summary>
        /// <param name="OrganizerId">The venue ID</param>
        /// <param name="VenueName">The venue name</param>
        /// <param name="VenueAdress">The venue adress</param>
        /// <param name="VenueCity">The venue city</param>
        /// <param name="VenueRegion">The venue state/province/county/territory depending on the country. 2-letter state code is required for US addresses</param>
        /// <returns>It returns the ID of the newly created venue</returns>
        public  Venue VenueUpdate(int VenueId, string VenueName, string VenueAdress, string VenueCity, string VenueRegion)
        {
            return new Venue(GetWebServiceResponseAsString(string.Format(UPDATE_VENUE_URL, CONNECTION_STRING, SecureClientCredentials(), VenueId, VenueName, VenueAdress, VenueCity, VenueRegion), 60000));
        }

        #endregion

        #region User Methods
        /// <summary>
        /// This method creates a new user.
        /// </summary>
        /// <returns>It returns the ID of the newly created user.</returns>
        public User UserNew(string email, string password) 
        {
            string url = string.Format(NEW_USER_URL, CONNECTION_STRING, email, password);
            return new User(GetWebServiceResponseAsString(url, 60000));
        }

		/// <summary>
        /// Only User which match login credentials are viewable.
        /// </summary>
        /// <param name="email">The email address of the subuser account.</param>
        /// <param name="password"></param>
        /// <returns>This method returns the data for a given user.</returns>
        public static User UserGetByMinimumCredentials(string appKey, string email, string password) 
        {
            string BasicClientCredentials = string.Format(BASIC_AUTHENTICATION_URL, appKey, email.Trim(), password);
            string url = string.Format(GET_USER_URL, CONNECTION_STRING, BasicClientCredentials);
            return new User(GetWebServiceResponseAsString(url, 60000));
        }

		/// <summary>
        /// This method lists the events created by this user. Only public events are returned if no authentication is passed.
        /// </summary>
        /// <param name="UserKey"></param>
        /// <returns></returns>
        public User UserListEvents(string UserKey) 
        {
            string url = string.Format(USER_LIST_EVENTS_URL, CONNECTION_STRING, SecureClientCredentials(UserKey));
            return new User(GetWebServiceResponseAsString(url, 60000));
        }


        public ContentServiceResponse<Organizers> UserListOrgenaizer(string email, string password)
		{
			string url = string.Format(USER_LIST_ORGENIZERS, CONNECTION_STRING,  SecureClientCredentials(),email, password);
            Logic.ContentServiceResponse<Organizers> response = new ContentServiceResponse<Organizers>();
			try
			{
				XmlDocument result = GetWebServiceResponseAsString(url, 60000);

                if (result.DocumentElement.Name == "organizers")
				{
                    response.Content = new Organizers(result); //result.DocumentElement["id"].InnerText;
					response.ResultOption = ServiceResultOptions.Success;
				}
				else
				{
					response.Message = result.DocumentElement["error_message"].InnerText;
					response.ResultOption = ServiceResultOptions.OperationFailure;
                    response.Content = null;
				}
			}
			catch (Exception ex)
			{
				response.ResultOption = ServiceResultOptions.SystemException;
                response.Content = null;
			}
			return response;
		}

        #endregion

        #region Service Communication Methods

        /// <summary>
        /// The simplest way to view the returned data is to get the response stream and put it into a string. This is especially handy for debugging. The following code gets a web page and returns the contents as a string. 
        /// </summary>
        /// <param name="url">The Exact request url</param>
        /// <param name="timeOut">The duration waiting for response from the service</param>
        /// <returns></returns>
        private  static XmlDocument GetWebServiceResponseAsString(string url, int timeOut)
        {
            XmlDocument xdoc = new XmlDocument();

            // Create the web request
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
            request.Method = "GET";
            request.Timeout = timeOut;

            // Get response 
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                // Get the response stream  
                StreamReader StreamReader = new StreamReader(response.GetResponseStream());
                //ResultText = StreamReader.ReadToEnd();
                xdoc.LoadXml(StreamReader.ReadToEnd());
            }

            return xdoc;
        }


        /// <summary>
        /// The secure method of authentication hides your login information and instead passes a user_key into the api.
        /// If a user_key provided, the API will validate it against the Eventbrite user database.
        /// If the user_key is valid and authenticated, the method call will continue. 
        /// If the user_key is not valid or presented an incorrect password and the method requires authentication, an XML error message is returned:
        /// To ensure maximum safety, only authentication requests made over SSL will be processed. 
        /// So all your API calls should start with "https://".
        /// </summary>
        /// <param name="UserKey">The user key is a unique string assigned by Eventbrite which identifies the user making an API call.
        /// This replaces basic username/password authentication.
        /// A valid user key is the recommended method for user authentication with the Eventbrite API.
        ///</param>
        /// <returns>the right SECURE AUTHENTICATION URL for the user</returns>
        private string SecureClientCredentials(string UserKey)
        {
            return string.Format(SECURE_AUTHENTICATION_URL, APP_KEY, UserKey);
        }
        
        /// <summary>
        /// The Basic level of authentication involves providing the parameters "user" and "password" to each method call along with other parameters.
        /// If a user and password are provided, the API will validate them against the Eventbrite user database.
        /// If the user is valid and authenticated, the method call will continue.
        /// If the user is not valid or presented an incorrect password and the method requires authentication, an XML error message is returned:
        /// To ensure maximum safety, only authentication requests made over SSL will be processed.
        /// So all your API calls should start with "https://".
        /// </summary>
        /// <param name="UserName">The current user name</param>
        /// <param name="Password">The current password</param>
        /// <returns>he right BASIC AUTHENTICATION URL for the user</returns>
        private string BasicClientCredentials(string email, string Password)
        {
            return string.Format(BASIC_AUTHENTICATION_URL, APP_KEY, email, Password);
        }


        private  string SecureClientCredentials()
        {
            return string.Format(SECURE_AUTHENTICATION_URL, APP_KEY, USER_KEY);
        }


        public  string SetDateFormat(DateTime dateTime)
        {
			return (dateTime.Year.ToString() + "-" + dateTime.Month.ToString() + "-" + dateTime.Day.ToString() + " " + dateTime.Hour + ":" + dateTime.Minute + ":" + dateTime.Second);
        }

        #endregion

    }

    public class EventBriteUtils
    {
        public static string CreateEventUrl(string eventID)
        {
            return "http://www.eventbrite.com/event/" + eventID;
        }
    }
}
